<template>
  <view class="container">
    <!-- 表单内容 -->
    <u-form class="form-content">
      <u-form-item label="监测站名称" class="form-item" label-width="120">
        <u-input
                v-model="formData.plateNumber"
                placeholder="请输入监测站名称"
                class="custom-input"
        />
      </u-form-item>
      <!-- 车牌号码输入 -->
      <u-form-item label="车牌号码" class="form-item" label-width="120">
        <u-input
          v-model="formData.plateNumber"
          placeholder="请输入车牌号码"
          class="custom-input"
        />
      </u-form-item>

      <!-- 车牌颜色选择 -->
      <u-form-item label="车牌颜色" class="form-item" label-width="120">
        <view class="arrow-icon-groud">
          <u-input
            class="custom-input"
            v-model="formData.plateColor"
            placeholder="请选择车牌颜色"
            @click="changeOpenCarColor"
          />
          <!-- 向下/向上箭头图标 -->
          <u-icon
            :name="plateColorPickerVisible ? 'arrow-up' : 'arrow-down'"
            size="20"
            class="arrow-icon"
          />
        </view>

        <area-picker
          ref="carPicker"
          :title="title"
          titleColor="#808080"
          titleFontSize="14px"
          cancelType="icon"
          cancelColor="#999999"
          cancleFontSize="28rpx"
          confirmColor="#2877FF"
          confirmFontSize="14px"
          confirmFontWeight="500"
          itemFontSize="14px"
          @onClose="closeCarPicker"
          @onConfirm="confirmCarPicker"
          :pickerList="list"
        />
      </u-form-item>

      <!-- 检测类别选择 -->
      <u-form-item label="检测类别" class="form-item" label-width="120">
        <view class="arrow-icon-groud">
          <u-input
                  class="custom-input"
                  v-model="formData.plateDetect"
                  placeholder="请选择检测类别"
                  @click="changeOpenDetect"
          />
          <!-- 向下/向上箭头图标 -->
          <u-icon
                  :name="plateColorPickerVisible ? 'arrow-up' : 'arrow-down'"
                  size="20"
                  class="arrow-icon"
          />
        </view>

        <area-picker
                ref="detectPicker"
                :title="titleDetect"
                titleColor="#808080"
                titleFontSize="14px"
                cancelType="icon"
                cancelColor="#999999"
                cancleFontSize="28rpx"
                confirmColor="#2877FF"
                confirmFontSize="14px"
                confirmFontWeight="500"
                itemFontSize="14px"
                @onClose="closeDetectPicker"
                @onConfirm="confirmDetectPicker"
                :pickerList="listDetect"
        />
      </u-form-item>
    </u-form>
    <!-- 查询按钮 -->
    <view class="btn-container">
      <u-button @click="submitForm">立即查询</u-button>
    </view>
  </view>
</template>

<script>
import areaPicker from "@/components/area-picker/area-picker.vue";
import { changePlatecolor, changeDetectType } from "@/common/util_complete.js";
export default {
  components: {
    areaPicker,
  },
  data() {
    return {
      title: "选择车牌颜色",
      titleDetect: "选择检测类别",
      formData: {
        plateNumber: "", // 车牌号码
        plateColor: "", // 车牌颜色
        plateDetect: "", // 车牌颜色
      },
      list: [], // 车牌颜色选择
      listDetect: [], //
    };
  },
  onLoad(options) {
    this.list = changePlatecolor(this.list);
    this.listDetect = changeDetectType(this.listDetect);
  },

  methods: {
    // 打开车牌颜色选择器
    changeOpenCarColor() {
      this.$refs.carPicker._open();
    },
    // 关闭选择器
    closeCarPicker() {
      this.$refs.carPicker._close();
    },
    confirmCarPicker(checkedValue) {
      this.formData.plateColor = checkedValue;
    },
    // 打开车牌颜色选择器
    changeOpenDetect() {
      this.$refs.detectPicker._open();
    },
    // 关闭选择器
    closeDetectPicker() {
      this.$refs.detectPicker._close();
    },
    confirmDetectPicker(checkedValue) {
      this.formData.plateDetect = checkedValue;
    },
    submitForm() {
      uni.navigateTo({
        url: "",
      });
      return;
    },
  },
};
</script>

<style scoped lang="scss">
.container {
  padding: 10px;
  background-color: #f3f6fa;
  height: 100vh;
  box-sizing: border-box;
}

.form-content {
  background-color: #ffffff;
  padding: 0;
  /* 去掉 padding */
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-item {
  padding: 0 10px;
  border-bottom: 1px solid #f1f1f1;
  /* 设置下边框 */
}

.custom-input {
  border: none;
  /* 去掉输入框的边框 */
  background-color: transparent;
  /* 使背景透明 */
}

.btn-container {
  margin-top: 30px;
  text-align: center;
  position: absolute;
  right: 0;
  padding: 0 20px;
  width: 100%;
  box-sizing: border-box;
  ::v-deep .u-button--info[data-v-461e713c] {
    width: 100%;
    background-color: #2877ff;
    color: #ffffff;
  }
}

.arrow-icon-groud {
  position: relative;
  flex: 1;

  .arrow-icon {
    position: absolute !important;
    right: 20px;
    top: 10px;
  }
}
</style>
